package util;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * Aspect called by spring for logging the method calls to the database.
 * @author Michel & Vincent
 *
 */
public class DatabaseLogger {

	/*
	 * For logging
	 */
	private static final Logger logger = Logger.getLogger(DatabaseLogger.class);
    
	public Object databaseCalled(ProceedingJoinPoint pjp) throws Throwable {
		
		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		long before = System.currentTimeMillis();

		// call the method
		Object o = pjp.proceed();
		long after = System.currentTimeMillis();

		String name = pjp.getSignature().getName();

		logger.info("CALL TO THE " + name + " METHOD : " + (after - before) + " ms");
		logger.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

		return o;
	}
}
